package com.qf.huigou.service.impl;

import com.qf.huigou.mapper.CartMapper;
import com.qf.huigou.mapper.GoodMapper;
import com.qf.huigou.pojo.Cart;
import com.qf.huigou.pojo.Good;

import com.qf.huigou.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 1.8.0_131
 * @Author WangYiZhu
 * @Email 2641956765@qq.com
 * @Time 2022/12/08 15:53
 */
@Service
public class GoodServiceImpl implements GoodService {
    @Autowired
    private GoodMapper goodMapper;

    @Autowired
    private CartMapper cartMapper;


    @Override
    public boolean addToCar2(int fk_cart_user_id,int fk_cart_good_id,int cart_good_price) {
        int insert= cartMapper.insert(fk_cart_user_id,fk_cart_good_id,cart_good_price);
        if (insert==1){
            return true;
        }
        return false;
    }
//    @Override
//    public boolean addToCar(Cart cart) {
//        int insert= cartMapper.insert(cart);
//        if (insert==1){
//            return true;
//        }
//        return false;
//    }

    @Override
    public Good getGoodToId(int goodId) {
        return goodMapper.selectByPrimaryKey(Long.valueOf(goodId));
    }

    @Override
    public List<Good> findGoodByCategoryOrBrandId(int category, int brandId) {
        return goodMapper.selectGoodByCateGoryIdOrBrandId(category,brandId);
    }

    /**
     * 一对多显示good商品信息
     * @param userId
     * @return
     */
    @Override
    public List<Cart> searchAllCart(int userId) {
        return cartMapper.searchAllCartByUserId(userId);
    }




    @Override
    public int deleteByCartId(int cartId) {
        return cartMapper.deleteByPrimaryKey(Long.valueOf(cartId));
    }
}
